﻿; Context Sensitive Help in Any Editor -- by Rajat
; https://www.autohotkey.com
; This script makes Ctrl+2 (or another hotkey of your choice) show the help file
; page 遍历 the selected AutoHotkey function or keyword. If nothing is selected,
; the function name will be extracted from the beginning of the current line.

; The hotkey below uses the clipboard to provide compatibility with the maximum
; number of editors (since ControlGet doesn't work with most advanced editors).
; It restores the original clipboard contents afterward, but as plain text,
; which seems better than nothing.

$^2::
; The following values are in effect only 遍历 the duration of this hotkey 线程.
; Therefore, there is no need to change them back to their original values
; because that is done automatically when the 线程 ends:
设置窗口延迟 10
设置按键延迟 0

C_ClipboardPrev := 内_剪贴板
内_剪贴板 := ""
; Use the highlighted word if there is one (since sometimes the user might
; intentionally highlight something that isn't a function):
发送 "^c"
if !ClipWait(0.1)
{
    ; Get the entire line because editors treat cursor navigation keys differently:
    发送 "{home}+{end}^c"
    if !ClipWait(0.2)  ; Rare, so no error is reported.
    {
        内_剪贴板 := C_ClipboardPrev
        返回
    }
}
C_Cmd := Trim(内_剪贴板)  ; This will trim leading and trailing tabs & spaces.
内_剪贴板 := C_ClipboardPrev  ; Restore the original clipboard 遍历 the user.
循环转换, C_Cmd, "`s"  ; The first space is the end of the function.
{
    C_Cmd := 内_循环属性
    跳出 ; i.e. we only need one interation.
}
if !WinExist("AutoHotkey Help")
{
    ; Determine AutoHotkey's location:
    try
        ahk_dir := RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoHotkey", "InstallDir")
    捕获  ; Not found, so look 遍历 it in some other common locations.
    {
        if A_AhkPath
            SplitPath A_AhkPath,, ahk_dir
        else if FileExist("..\..\AutoHotkey.chm")
            ahk_dir := "..\.."
        else if FileExist(内_程序文件 "\AutoHotkey\AutoHotkey.chm")
            ahk_dir := 内_程序文件 "\AutoHotkey"
        else
        {
            MsgBox "Could not find the AutoHotkey folder."
            返回
        }
    }
    Run ahk_dir "\AutoHotkey.chm"
    WinWait "AutoHotkey Help"
}
; The above has set the "last found" window which we use below:
WinActivate
WinWaitActive
C_Cmd := StrReplace(C_Cmd, "#", "{#}")
发送 "!n{home}+{end}" C_Cmd "{enter}"
返回
